package homework.mission5;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

public class PokerDemo {
    public static void main(String[] args) {
        // 创建一个 map 集合来存放扑克牌的编号 和 是什么牌
        HashMap<Integer, String> map = new HashMap<Integer, String>();

        // 声明一个 ArrayList 来存放扑克牌的编号
        ArrayList<Integer> array = new ArrayList<Integer>();

        //创建花色数组和点数数组
        String[] colors = {"♠","♥","♣","♦"};
        //定义一个点数数组
        String[] numbers = {"2","A","K","Q","J","10","9","8","7","6","5","4","3"};


        map.put(0, "大王");
        array.add(0);
        map.put(1, "小王");
        array.add(1);

        // 表示当前添加牌的索引
        int index = 2;
        for (String color : colors) {
            for (String number : numbers) {
                // 生成牌
                String poker = color.concat(number);

                // 当前牌的编号和具体是什么牌添加到 map 集合中
                map.put(index, poker);
                array.add(index);
                index ++;
            }
        }

        // 洗牌
        Collections.shuffle(array);

        TreeSet<Integer> player1 = new TreeSet<Integer>();
        TreeSet<Integer> player2 = new TreeSet<Integer>();
        TreeSet<Integer> player3 = new TreeSet<Integer>();
        TreeSet<Integer> dipai = new TreeSet<Integer>();

        // 发牌
        for (int i = 0; i < array.size(); i++) {
            if(i >= array.size() - 3) { // 最后三张底牌
                dipai.add(array.get(i));
            } else if(i % 3 == 0) {
                player1.add(array.get(i));
            } else if(i % 3 == 1) {
                player2.add(array.get(i));
            } else if(i % 3 == 2) {
                player3.add(array.get(i));
            }
        }

        lookPoker("玩家一", player1, map);
        lookPoker("玩家二", player2, map);
        lookPoker("玩家三", player3, map);
        lookPoker("底牌", dipai, map);
    }

    public static void lookPoker(String name, TreeSet<Integer> ts, HashMap<Integer, String> map) {
        System.out.print(name + " 的牌是：");
        for (Integer key : ts) {
            String poker = map.get(key);
            System.out.print(poker + "");
        }
        System.out.println();
    }
}
